/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package assign2;

import java.io.*;
import java.net.*;

/**
 *
 * @author martyastiadi
 */
public class Client {

    protected String host;
    protected int port;

    public Client(String host, int port) {
        this.host = host;
        this.port = port;
    }

    public void connect() {
        try {
            Socket clientSocket = new Socket(host, port);
            handleConnection(clientSocket);
        } catch (IOException e) {
            System.out.println("client connect exception: " + e);
        }
    }

    /* Repeatedly read data from socket and write to user's screen. */
    protected void handleConnection(Socket clientSocket)
            throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        String response;
        while ((response = in.readLine()) != null) {
            System.out.println(response);
        }
        clientSocket.close();
    }
}
